/**
 * StringOutputStream.java
 *
 *  charset : UTF-8
 *  created : 23.8.2011
 */
package utils;

import java.io.ByteArrayOutputStream;
import java.io.FilterOutputStream;
import java.io.IOException;

/**  
 * OutputStream, který pouze zapisuje do řetězce.
 * 
 * @author Martin Pokorný
 * @version 0.1
 */
public class StringOutputStream extends FilterOutputStream  {
    StringBuilder sb = new StringBuilder();
    
    public StringOutputStream() {
        super(new ByteArrayOutputStream());
    }
    
    @Override
    public void write(byte[] b) throws IOException {
        super.write(b);
        sb.append(new String(b));
    }
    @Override
    public void write(byte[] b, int off, int len) throws IOException {
        super.write(b, off, len);
        sb.append(new String(b,off,len));
    }        
    
    public String getString() {
        return sb.toString();
    }
    @Override
    public String toString() {
        return sb.toString();
    }
    
}   // StringOutputStream
